package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author fan
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    private BorrowerService borrowerService;

    @GetMapping("/list/{page}/{limit}")
    public R getPageList(@PathVariable("page") Long page, @PathVariable("limit") Long limit,String keyword){
        Page<Borrower> borrowerPage = borrowerService.getPageList(page,limit,keyword);
        return R.ok().data("pageModel",borrowerPage);
    }
    @GetMapping("/getStatus/{id}")
    public R getStatus(@PathVariable("id") Long id){
        Integer status = borrowerService.getStatus(id);
        return R.ok().data("status",status);
    }
    @GetMapping("/show/{id}")
    public R getBorrowerDetail(@PathVariable("id") Long id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetail(id);
        return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }
    @PostMapping("/approval")
    public R saveApproval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        Long id = borrowerApprovalVO.getBorrowerId();

        borrowerService.saveApproval(borrowerApprovalVO);
        return R.ok();
    }
}

